#include <iostream>
#include <vector>
#include <math.h>
using namespace std;
class Solution
{
public:
    /**
     * @brief
     * 1 <= left <= right <= 10^6
     * 0 <= right - left <= 10^4
     *
     * @param left
     * @param right
     * @return int
     */
    int countPrimeSetBits(int left, int right)
    {
        int ansCount = 0;
        for (int i = left; i <= right; i++)
        {
            int num = i, bitsCount = 0;
            while (num)
            {
                num &= num - 1;
                bitsCount++;
            }
            if (isPrime(bitsCount))
            {
                ansCount++;
            }
        }
        return ansCount;
    }

    bool isPrime(int num)
    {

        if (2 > num)
        {
            return false;
        }
        for (int i = 2; i <= sqrt(num); i++)
        {
            if (num != i && num % i == 0)
            {
                return false;
            }
        }
        return true;
    }

    int countPrimeSetBits_2(int left, int right)
    {
        int count = 0;
        while (left <= right)
        {
            count += 665772 >> __builtin_popcount(left++) & 1;
        }
        return count;
    }

    int countPrimeSetBits_3(int left, int right)
    {
        bool isPrime[32] = {0,
                            0, 1, 1, 0, 1, 0, 1, 0, 0, 0,
                            1, 0, 1, 0, 0, 0, 1, 0, 1, 0,
                            0, 0, 1, 0, 0, 0, 0, 0, 1, 0,
                            1};

        int N = 0;
        for (int i = left; i <= right; ++i)
        {
            if (isPrime[__builtin_popcount(i)])
                ++N;
        }
        return N;
    }
};
int main()
{
    Solution s;
    // cout << s.isPrime(6) << endl;
    cout << s.countPrimeSetBits_2(10, 15) << endl;
    return 0;
}
